import { deepCopy } from '@/libs/util';
const filters = {
    "8": {
        filterValue: {
            username: "",
            status: 0,
            created_at: ''
        },
        filterData: [
            { title: "input", field_name: "username", field_type: "input" },
            {
                title: "select", field_name: "status", field_type: "select", options: [
                    {
                        value: 0,
                        label: "全部"
                    },
                    {
                        value: 1,
                        label: "进行中"
                    },
                    {
                        value: 2,
                        label: "拼团成功"
                    },
                    {
                        value: 2,
                        label: "拼团失败"
                    }
                ]
            },
            { title: "datarange", field_name: "created_at", field_type: "datarange" }
        ]
    }
}
export default {
    data() {
        return {
            modalWidth: 500,
            modalOutHeight: 353,
            filterValue: {},
            filterData: [],
            importVisible: false
        }
    },
    created() {
        this.filterValue = Object.assign({}, filters[this.formId].filterValue);
        this.filterData = deepCopy(filters[this.formId]).filterData;
    },
    methods: {
        makeData(fieldName) {
            return filters[this.formId][fieldName];
        },
        filterMethod() {
            const filters = [];

            this.filterData.forEach(filter => {
                if (filter.field_type === "input") {
                    if (this.filterValue[filter.field_name].length > 0) {
                        filters.push({
                            field_name: filter.field_name,
                            type: filter.field_name == 'goods_stocks' ? 9 : 3,
                            value: this.filterValue[filter.field_name],
                            field_type: "text"
                        });
                    }
                } else if (filter.field_type === "datarange") {
                    if (this.filterValue.stime) {
                        filters.push({
                            field_name: this.formId == 13 ? "stime" : filter.field_name,
                            type: 7,
                            value: Math.round(new Date(this.filterValue.stime).getTime() / 1000).toString(),
                            field_type: "datetime"
                        });
                    }

                    if (this.filterValue.etime) {
                        filters.push({
                            field_name: this.formId == 13 ? "etime" : filter.field_name,
                            type: 9,
                            value: Math.round(new Date(this.filterValue.etime).getTime() / 1000).toString(),
                            field_type: "datetime"
                        });
                    }
                } else if (filter.field_type === "select") {
                    if (this.filterValue[filter.field_name] > 0) {
                        filters.push({
                            field_name: filter.field_name,
                            type: 1,
                            value: this.filterValue[filter.field_name],
                            field_type: "number"
                        });
                    }
                }
            });

            return filters;
        },
        handleImport() {
            this.importVisible = true;
        },
        handleClearFilter() {
            this.filterValue = Object.assign({}, filters[this.formId].filterValue);
        }
    }
};